// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var constant = require("constant");
    var css_detail = require("./commissionExtractDetail.css");
    var databind = require("databind");
    var extractId;
    var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
    
    var init = function(page){
    	extractId = page.params.extractId;
		inquireCommissionExtractApplicationDetail(extractId);
    	router.init();
		initEvent();
    };
    
	var initEvent = function(){
		if(base.getData("sid")==null){
			location.href="../login/login.html";
		}
    };
    
    var inquireFinanceCommissionInfoList = function(extractId) {
		base.fnAjax({
			action: "inquireFinanceCommissionInfoList.json",
			oData: {
				extractId: extractId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {

					juicer.register("getValueByKey", constant.getValueByKey);

					var tpl1 = $("#commissionTpl").html();
					var html1 = juicer(tpl1, data);
					$("#commissionTable").html(html1);
					
					$("#commissionExtractDetail .detail").unbind("click").click(function(){
						router.route("account/commissionDetail.html?financeId="+$(this).parents("tr").attr("financeId") + "&expenseItem=佣金");
					});

				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	//佣金提取详情
	var inquireCommissionExtractApplicationDetail = function(extractId) {
		base.fnAjax({
			action: "inquireCommissionExtractApplicationDetail.json",
			oData: {
				extractId: extractId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($("#commissionExtractDetail"), data.datas[0]);
					inquireFinanceCommissionInfoList(extractId);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
    return {
        init:init
    };
});